package com.example.service;

import com.example.entity.Exam;
import com.example.mapper.ExamMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 考试信息表业务处理
 **/
@Service
public class ExamService {

    @Resource
    private ExamMapper examMapper;

    /**
     * 新增
     */
    public void add(Exam exam) {
        examMapper.insert(exam);
    }

    /**
     * 删除
     */
    public void deleteById(Integer id) {
        examMapper.deleteById(id);
    }

    /**
     * 批量删除
     */
    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            examMapper.deleteById(id);
        }
    }

    /**
     * 修改
     */
    public void updateById(Exam exam) {
        examMapper.updateById(exam);
    }

    /**
     * 根据ID查询
     */
    public Exam selectById(Integer id) {
        return examMapper.selectById(id);
    }

    /**
     * 查询所有
     */
    public List<Exam> selectAll(Exam exam) {
        return examMapper.selectAll(exam);
    }
    public List<Exam> selectByUserId(Exam exam,Integer userId) {
        return examMapper.selectByUserId(exam,userId);
    }

    /**
     * 分页查询
     */
    public PageInfo<Exam> selectPage(Exam exam, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Exam> list = examMapper.selectAll(exam);
        return PageInfo.of(list);
    }

}